package com.example.springmvcdemo;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/headerSet")
@Controller
public class headerSet {
    @RequestMapping(value = "r1",produces = "application/json;charset=UTF-8")
    //这里定义了响应的类型 produces
    //后面设置的是编码
    @ResponseBody
    public String r1(){
        return "{\"status\":400}";//json,里面要有转义字符串
    }

    @ResponseBody
    @RequestMapping("/s1")
    public String setHeader(HttpServletResponse response){
        response.setHeader("myHeader","myHeaderValue");
        return "set successfully";
    }
}
